/*=====================================================================================
* Copyright (c) 2020, micROS Group, NIIDT, TAIIC.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
*  provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
*      the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
*      and the following disclaimer in the documentation and/or other materials provided with the
*      distribution.
* 3. All advertising materials mentioning features or use of this software must display the following
*      acknowledgement: This product includes software developed by the micROS Group and its
*      contributors.
* 4. Neither the name of the Group nor the names of contributors may be used to endorse or promote
*     products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY MICROS GROUP AND CONTRIBUTORS ''AS IS''AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE MICROS, GROUP OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
*  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=====================================================================================
*/

#ifndef __OPTICAL_CLIP_DETECTOR_H
#define __OPTICAL_CLIP_DETECTOR_H

#include <string>
#include <vector>
#include <numeric>
#include "opencv2/opencv.hpp"
#include <acl/acl.h>


  class Yolov3CLIPDetector 
  {
  public:
    Yolov3CLIPDetector();
    ~Yolov3CLIPDetector();
    bool Initialize(const std::string& modelpath);
    bool inference(cv::Mat &img);                 
    bool initEngine(const std::string& enginePath);
    void DestroyInput();
    bool engineInfer(std::vector<float>&input_data, uint32_t fileSize);
    void image_preprocess(cv::Mat &src_image, std::vector<float>&input_data);
    std::vector<float> softmax(std::vector<float> &conf, float temperature=100);
    std::vector<float> means{0.48145466, 0.4578275,0.40821073};
    std::vector<float> stds{0.26862954, 0.26130258, 0.27577711};

  private:
    uint32_t modelId;
    aclmdlDataset *input = nullptr;
    aclmdlDataset *output = nullptr;
    void* outputDeviceData = nullptr;
    void* pictureDeviceData = nullptr;
    aclDataBuffer *outputData = nullptr;
    aclDataBuffer* inputBuffer = nullptr;
    aclDataBuffer* batchBuffer = nullptr;
    void* outputHostData = nullptr;
    aclmdlDesc *modelDesc;
    aclrtRunMode runMode;
    size_t clipWidth=224, clipHeight=224;
    size_t deviceId=0;
    size_t modelOutputSize = 0;
    size_t fileSize;
  };
#endif



